home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Communications / General / LineShare Folder / Put Onto Productions Disks / LineShare Scripts / Fax Class2&ARA&Data < prev    next >
Text File  |  1994-04-28  |  8KB  |  431 lines

  1. ! Version 3.0.2
  2. !
  3. !$ Use this script with Class 2 fax software, ARA 1.0 or 2.0,
  4. !$ and a BBS, E-mail or other communication server software
  5. !
  6. !$ A cable for hardware handshaking is required
  7.  
  8. ^# Modem:
  9. ^2 Fax Software: = Enum("FaxSTF™"="0","4-Sight™"="1","Delrina"="2","Glenwarne sw/hsk"="3","Glenwarne hw/hsk"="4") "0"
  10. ^3 Error Correction: = Bool("Enabled"="AUTO","Disabled"="NORM") "NORM"
  11. ^4 Handshake wires: = Bool("CTS+DTR"="&D0","CTS only"="&D2") "&D2"
  12. ^5 Answer On: = Enum("Never"="0","1 Ring"="1","2 Rings"="2","3 Rings"="3","5 Rings"="5","7 Rings"="7") "2"
  13. ! ------------------------------------------
  14. ! Resetting the modem:
  15. ! ------------------------------------------
  16. @Hangup
  17.   SetTries 2
  18.   Flush
  19.   HsReset 0,0,0,0,0,0
  20. !
  21. ! Try to catch the "OK" answer, use the Escape seq and DTR transitions
  22. ! to enter the command mode
  23. !
  24. @Label 1
  25.   matchclr
  26.   matchstr 1 2 "OK\r\n"
  27.   write "ATH0V1Q0\r"
  28.   matchread 20
  29.   ChrDelay 1
  30.   Write "+++"
  31.   ChrDelay 0
  32.   DtrClear
  33.   SBreak
  34.   DtrSet
  35. !
  36.   DecTries
  37.   IfTries 0 1
  38. !
  39. ! OSErr -6019 "Modem error - the modem is not responding"
  40. !
  41.   exit -6019
  42. @Label 2
  43.   SetVar A "&F"
  44.   GetOption A "DFLT" 3
  45. @Label 3
  46.   write "AT^A+FCLASS=0;+FAA=0\r"
  47.   Jsr 100
  48.   exit 0
  49.  
  50. @Label 6
  51.   Say "This script cannot be used with this modem"
  52.   ifOriginate 7
  53.   pause 1800
  54. @Label 7
  55.   exit -6019
  56. ! ------------------------------------------
  57. !    Receiving incoming calls
  58. ! ------------------------------------------
  59. @ANSWER
  60. @Label 10
  61. !
  62. ! Set the modem preferred speed first
  63.   SerReset 19200,0,8,1
  64.   Jsr 80
  65. !
  66. ! Set the common options
  67.   Jsr 70
  68. !
  69. ! Set the communication options:
  70. ! • Normal/AUTO Connection
  71. ! • HW flow control  (for ARA, Fax should not use a handshake on receiving)
  72. ! • CONNECT <DCE speed> or CARRIER/CONNECT
  73. !
  74.   GetOption A "HWHS" 6
  75.   GetOption B "^3" 6
  76.   GetOption C "LNRS" 6
  77.   Write "AT^A^B^C\r"
  78.   Jsr 100
  79. !
  80. ! Set Fax parameters: LID, DCC,BOR
  81. !
  82.   Write "AT+FCLASS=2;+FCR=1;+FAA=1\r"
  83.   Jsr 100
  84. !
  85. ! Set FLID - sometimes it can fail
  86. !
  87.   GetCommand A "Fax" "+FLID="
  88.   Write "AT^A\r"
  89.   MatchClr
  90.   MatchStr 1 11 "OK\r\n"
  91.   MatchRead 10
  92. @Label 11
  93.   Write "AT+FDCC=1,3,0,2,0,0,0,0\r"
  94.   Jsr 100
  95.   GetCommand A "Fax" "+FDCC="
  96.   Write "AT^A\r"
  97.   Jsr 100
  98.   GetCommand A "Fax" "+FBOR="
  99.   Write "AT^A\r"
  100.   Jsr 100
  101. !
  102. ! It's for Rockwell ONLY! Set FCLASS to 0 again
  103.   GetOption A "RCWL" 12
  104.   Write "AT+FCLASS=0\r"
  105.   Jsr 100
  106. @Label 12
  107. !
  108. ! Get the Speaker and the Ring Num options
  109.   GetCommand B "Fax" "M"
  110.   GetCommand C "Fax" "L"
  111.   GetCommand D "Fax" "S0"
  112. !  SetVar A "S0=2"
  113. !  ifStr D 13 "S0=0"
  114. !  ifStr D 13 ""
  115. !  SetVar A "^D"
  116. !@Label 13
  117.    SetVar A "S0=^5"
  118. !
  119. ! Fetch the tube after <A> rings
  120.   Write "AT^A^B^C\r"
  121.   Jsr 100
  122. !
  123. ! Everything is ready - let's sit and wait for a call
  124. ! We'll wait for 2 minutes, then reinitiate the modem
  125.   Note "Waiting for a Fax/ARA/Data call…"
  126.   Jsr 90
  127.   IfStr D 40 "FAX"
  128.   IfStr D 20 "DATA"
  129.   Jump 10
  130.  
  131. !
  132. ! Data connection has been established (we read "CONNECT")
  133. ! Put the "CONNECT" back to the buffer and attach the "Data" subPort
  134. ! if it was an incoming call, put the "RING" before the "CONNECT"
  135. !
  136. @Label 20
  137.   IfOpen "Data" 21
  138.   Jump 30
  139. @Label 21
  140.   IfOpen "ARA" 22
  141.   Jump 35
  142. @Label 22
  143.   Note "Waiting for an ARA frame"
  144.   MatchClr
  145.   MatchStr 1 23 "^$\r"
  146.   MatchStr 2 28 "\08\01\03\14\04\03\00\08\250\16\03"
  147.   MatchStr 3 29 "\01\27\02\29\01\02\01\06"
  148.   MatchRead 40
  149.   Jump 24
  150. @Label 23
  151.   QueueInput "^$\r"
  152. @Label 24
  153.   Note "Non-ARA call"
  154.   Jump 35
  155.  
  156. @Label 28
  157.   Note "ARA 1.0 call"
  158.   Jump 30
  159. @Label 29
  160.   Note "ARA 2.0 call"
  161.   Jump 30
  162.  
  163. @Label 30
  164.   QueueInput "\r\nCARRIER ^B\r\n"  
  165.   IfStr A 31 "NONE"
  166.   IfStr A 31 "None"
  167.   QueueInput "\r\nREL\r\n"
  168. @Label 31
  169.   IfOriginate 32
  170.   QueueInput "\r\nRING\r\n"
  171. @Label 32
  172.   Attach "ARA" (DTR)
  173.  
  174. @Label 35
  175.   GetSReg C "DATA" 4
  176.   QueueInput "\r^CCONNECT ^B\r^C"
  177.   ifOriginate 36
  178.   QueueInput "\r^CRING\r^C"
  179. @Label 36
  180.   HsReset 0,1,0,0,0,1
  181.   Attach "Data" (DTR,Escape,Break)
  182.  
  183. !
  184. ! Fax connection has been established (we read "+FCON")
  185. ! Put the +FCON back to the buffer,
  186. ! if it was an incoming call, put the "RING" before the "+FCON"
  187. ! Attach the "Fax" subPort
  188. !
  189. @Label 40
  190.   QueueInput "\r\n+FCON"
  191.   ifOriginate 41
  192.   QueueInput "\r\nRING\r\n"
  193. @Label 41
  194.   IfStr 2 42 "0"
  195.   IfStr 2 42 "3"
  196.   IfStr 2 42 "4"
  197.   Attach "Fax" (DTR,IdleLimit=30)
  198. @Label 42
  199.   Attach "Fax" (DTR,Reset,IdleLimit=30)
  200.  
  201. ! ------------------------------------------
  202. ! Originating a call through the "ARA" subport
  203. ! ------------------------------------------
  204. @ORIGINATE "ARA"
  205.   SerReset 19200,0,8,1
  206.   Jsr 80
  207. !
  208. ! Set the common options
  209.   Jsr 70
  210. !
  211. ! Set the communication options:
  212. ! • Normal Connection
  213. ! • HW flow control
  214. ! • CONNECT <DCE speed> or CARRIER/CONNECT
  215. !
  216.   GetOption A "HWHS" 6
  217.   GetOption B "^3" 6
  218.   GetOption C "LNRS" 6
  219.   Write "AT^A^B^C\r"
  220.   Jsr 100
  221. !
  222. ! dial the number
  223.   Write "ATD^1\r"
  224. !
  225. ! Wait for a modem response
  226.   Jsr 90
  227.   IfStr D 30 "DATA"
  228.   Write "\r"
  229.   Exit -6019
  230.  
  231. ! ------------------------------------------
  232. ! Originating a call through the "DATA" subport
  233. ! ------------------------------------------
  234. @ORIGINATE "Data" ("\r\nLineShare Line is Busy\r\nBUSY\r\n")
  235.   SerReset 19200,0,8,1
  236.   Jsr 80
  237. !
  238. ! Set the common options
  239.   Jsr 70
  240. !
  241. ! Set the communication options:
  242. ! • Normal Connection
  243. ! • HW flow control
  244. ! • CONNECT <DCE speed> or CARRIER/CONNECT
  245. !
  246.   GetOption A "HWHS" 6
  247.   GetOption B "^3" 6
  248.   GetOption C "LNRS" 6
  249.   Write "AT^A^B^C\r"
  250.   Jsr 100
  251. !
  252. ! dial the number
  253.   Write "ATD^1\r"
  254.   HsReset *
  255. !
  256. ! Wait for a modem response
  257.   Jsr 90
  258.   IfStr D 35 "DATA"
  259.   Write "\r"
  260.   Exit -6019
  261.  
  262. ! ------------------------------------------
  263. ! Originating a call through the "Fax" subPort
  264. ! ------------------------------------------
  265. @ORIGINATE "Fax" ("\r\nLineShare Line is Busy\r\nBUSY\r\n")
  266. !
  267. ! Set the "Fax" speed
  268. !
  269.   SerReset 19200,0,8,1
  270.   Jsr 80
  271. !
  272. ! Set the common options
  273. !
  274.   Jsr 70
  275. !
  276. ! Now emit all commands that the application has sent to that port,
  277. ! except "V" and "+FCLASS"
  278. !
  279.   EmitClear "V","+FCLASS"
  280.   Jsr 60
  281.   Write "AT+FCLASS=2\r"
  282.   Jsr 100
  283. !
  284. ! setting the handshaking mode for faxing
  285.   ifStr 2 50 "3"
  286.   ifStr 2 51 "4"
  287.   HsReset *
  288.   Jump 53
  289. @Label 50
  290.   HSReset 1,0,17,19,1,0
  291.   GetOption A "SWHS" 6
  292.   Jump 52
  293. @Label 51
  294.   HSReset 0,1,0,0,0,0
  295.   GetOption A "HWHS" 6
  296. @Label 52
  297.   Write "AT^A\r"
  298.   Jsr 100
  299. @Label 53
  300. !
  301. ! dialing the number
  302.   Write "ATD^1\r"
  303.   Jsr 90
  304.   IfStr D 40 "FAX"
  305.   Write "\r"
  306.   Exit -6019
  307. !
  308. ! This section emits all modem commands sent from the client application
  309. ! For each set of commands the "OK" answer is awaited
  310. !
  311. @Label 60
  312.   EmitStart
  313. @Label 61
  314.   EmitCommand 62
  315.   Jsr 100
  316.   Jump 61
  317. @Label 62
  318.   return
  319. !
  320. ! This section initiates the modem before ANSWER and ORIGINATEs:
  321. ! reset on Dtr drop + DCD valid
  322. ! Verbal responses mode, no echo 
  323. !
  324. @Label 70
  325.   Write "AT^4&C1V1E0\r"
  326.   Jsr 100
  327.   return 
  328.  
  329. !
  330. ! This section syncronize the modem after the serial port speed switching
  331. !
  332. @Label 80
  333.   ChrDelay 1
  334.   Write "AT\r"
  335.   ChrDelay 0
  336.   Jsr 100
  337.   return
  338. !
  339. ! Error codes
  340. @Label 81
  341.   exit -6020
  342. @Label 82
  343.   exit -6022
  344. @Label 83
  345.   exit -6021
  346. @Label 84
  347.   exit -6023
  348.   
  349. !
  350. ! This subroutine waits for the modem response
  351. ! On exit, ^D contains the result code: "FAX" or "DATA"
  352. ! ^A contains the protocol used
  353. ! ^B contains the carrier speed
  354. ! If modem reports an error, the scripts exits with an error code
  355. !
  356. @Label 89
  357.   Note "Ring…"
  358.   Jump 91
  359.  
  360. @Label 90
  361.   SetVar A "NONE"
  362.   SetVar B ""
  363.   MatchClr
  364.   Matchstr 1 92 "CARRIER ^$\r\n"
  365.   Matchstr 2 93 "PROTOCOL: ^$\r\n"
  366.   Matchstr 3 94 "+FCON"
  367.  
  368.   Matchstr 4 95 "CONNECT ^$/"
  369.   Matchstr 5 97 "CONNECT ^$\r\n"
  370.   Matchstr 6 89 "RING\r\n"
  371.   Matchstr 10 82 "BUSY\r\n"
  372.   MatchStr 11 83 "NO CARRIER\r\n"
  373.   MatchStr 12 84 "NO ANSWER\r\n"
  374.   MatchStr 13 81 "NO DIALTONE\r\n"
  375. @Label 91
  376.   Matchread 1200
  377.   SetVar D "NONE"
  378.   return
  379.  
  380. @Label 92
  381.   SetVar B "^$"
  382.   Jump 91
  383. @Label 93
  384.   SetVar A "^$"
  385.   Jump 91
  386. !
  387. ! Fax connection was established
  388. !
  389. @Label 94
  390.   SetVar D "FAX"
  391.   return
  392.  
  393. ! CONNECT xxxx/XXXX was detected
  394. @Label 95
  395.   Jsr 98
  396.   MatchClr
  397.   MatchStr 1 96 "^$\r\n"
  398.   MatcRead 10
  399. @Label 96
  400.   SetVar A "^$"
  401.   SetVar D "DATA"
  402.   return
  403.  
  404. ! CONNECT xxx was detected
  405. @Label 97
  406.   Jsr 98
  407.   SetVar D "DATA"
  408.   return
  409.  
  410. @Label 98
  411.   ifStr B 99 ""
  412.   return
  413. @Label 99
  414.   SetVar B "^$"
  415.   return 
  416. !
  417. ! Processing the AT command:
  418. ! OK -> proceed
  419. ! ERROR or TimeOut ->exit -6019
  420. ! It can be called AFTER the "Write" command, since LineShare buffers input
  421. !
  422. @Label 100
  423.   MatchClr
  424.   MatchStr 1 102 "OK\r\n"
  425.   MatchStr 2 101 "ERROR\r\n"
  426.   MatchRead 20
  427. @Label 101
  428.   Exit -6019
  429. @Label 102
  430.   return
  431.